package com.evil.common.application.dto.order.data;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 控件值 实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@Accessors(chain = true)
public class ControlDataValueDTO {

    /**
     * 选择项id
     */
    private Long id;

    /**
     * 选择项ids 单个数据 选择多个选项，比如级联选择 开启了多选
     */
    private List<Long> ids;

    /**
     * 值
     */
    private String value;

    /**
     * 搜索引擎值
     */
    private String dataValue;

    /**
     * 值（邮箱）
     */
    private String email;

    /**
     * 字典
     */
    private String ordinal;

    /**
     * 其他信息
     */
    private Object otherInfo;

    /**
     * 值（插件）
     */
    private String pluginValue;

    public ControlDataValueDTO() {
    }

    public ControlDataValueDTO(Long id, String dataValue) {
        this.id = id;
        this.dataValue = dataValue;
    }

    public ControlDataValueDTO(List<Long> ids, String dataValue) {
        this.ids = ids;
        this.dataValue = dataValue;
    }

    public ControlDataValueDTO(String value) {
        this.value = value;
        this.dataValue = value;
    }

    public ControlDataValueDTO copy() {
        return BeanUtil.copyProperties(this, ControlDataValueDTO.class);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ControlDataValueDTO that = (ControlDataValueDTO) o;
        return Objects.equals(id, that.id)
                && Objects.equals(ids, that.ids)
                && Objects.equals(value, that.value)
                && Objects.equals(email, that.email)
                && Objects.equals(ordinal, that.ordinal)
                && Objects.equals(otherInfo, that.otherInfo)
                && Objects.equals(pluginValue, that.pluginValue);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, ids, value, email, ordinal, otherInfo, pluginValue);
    }

    public static List<ControlDataValueDTO> copy(List<ControlDataValueDTO> values) {
        return values.stream().map(e -> e.copy()).collect(Collectors.toList());
    }
}
